package com.codemeta.bokit.comm.enums;

import cn.hutool.core.collection.ListUtil;
import com.codemeta.bokit.comm.validation.InEnumKey;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 注册来源枚举
 *
 * @author apple
 */
@Getter
@AllArgsConstructor
public enum RegisterSource implements InEnumKey {
    /**
     * 0未知
     */
    unknown(0),
    /**
     * 1邮箱
     */
    email(1),
    /**
     * 2手机号
     */
    mobile(2),
    /**
     * 3用户名
     */
    username(3),
    /**
     * 4微信
     */
    weixin(4),
    /**
     * 5抖音
     */
    douyin(5),
    ;
    private final int value;

    @Override
    public Set<String> keys() {
        return Arrays.stream(values()).map(r -> String.valueOf(r.getValue())).collect(Collectors.toSet());
    }

    /**
     * 根据just-auth开源组件type类型匹配
     *
     * @param justAuthType .
     * @return .
     */
    public static RegisterSource fromJustAuth(String justAuthType) {
        if (ListUtil.of("WECHAT_OPEN", "WECHAT_MP", "WECHAT_ENTERPRISE").contains(justAuthType.toUpperCase())) {
            return weixin;
        } else if ("DOUYIN".equalsIgnoreCase(justAuthType)) {
            return douyin;
        } else {
            return unknown;
        }
    }

}